# 给定一个整数数组 nums 和一个整数目标值 target，请你在该数组中找出 和为目标值 target 的那 两个 整数，并返回它们的数组下标。
import time


# 你可以假设每种输入只会对应一个答案。但是，数组中同一个元素在答案里不能重复出现。

# 你可以按任意顺序返回答案。

def two_Sum(nums, target):
    # 极速版  000558376312256
    # result = []
    # for i in range(len(nums)):
    #     for j in range(i + 1, len(nums)):
    #         if nums[i] + nums[j] == target:
    #             result.append(i)
    #             result.append(j)
    # return result
    # 缓慢版  001103401184082
    ready = []
    num_dict = []
    for index, value in enumerate(nums):
        if target - value not in ready:
            num_dict.append(value)
            if ((target - value != value) & (value <= target) & (num_dict.count(value) == 1) & (target-value in nums)) or ((value + value == target) & (nums.count(value) == 2)):
                ready.append(index)
    return ready


if __name__ == "__main__":
    s_time = time.time()
    time.sleep(2)
    # nums = [2, 3, 4]
    # target = 6
    nums = [2, 7, 9, 15]
    target = 9
    print(two_Sum(nums, target))
    e_time = time.time()
    print('time cost: ', (e_time - s_time))
